Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let amend mode load previous commit message even if the editor's working dir is outside the repo #201

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bonderado
Copy link

I often work with repositories that depend on each other, but are meant to reside in sibling directories (I cannot change this structure).
To make grepping all the repositories at once, I usually start neovim from the common parent directory, but then trying to amend a commit with CA, fails to load the previous message as described in #200.

This pull request tries to address this by invoking fnamemodify(git_dir, ':p') on the path returned by the previous call to
git rev-parse --git-dir
making it absolute.

In my tests this approach works when opening the file from:

  • the parent directory,
  • a sibling directory and,
  • a path with an ancestor in common with the containing repository.

The path to the ".git" directory returned by
git rev-parse --git-dir
and stored in "b:magit_git_dir", can be a relative one, which would not work for opening file
"COMMIT_EDITMSG" when the currently edited file was opened from outside the
repository, so we make "b:magit_git_dir" absolute via "git rev-parse --absolute-git-dir".

Thanks to user v-slava for suggesting the use of --absolute-git-dir.
@bonderado bonderado changed the base branch from next to master May 29, 2024 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant